Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 743 multi file and 744 debsign support #782

Merged
merged 11 commits into from
Oct 12, 2021

Conversation

g-k
Copy link
Contributor

@g-k g-k commented Oct 4, 2021

fix #743 multiple file signing
fix #744 debsign support

Note: this is a combined PR since an interface without an implementation wasn't terribly useful.

Changes:

Implement support for signing multiple files #743

  • Add optional files field to the signature request format in 570472e
  • Add optional signed_files field to the signature response format in 2a964b8
  • Add a named file format with docs and an example:
[
    {
        "content": "UEsDBBQACAAIAAAAAAAAAAAAAAAAAAAAAAATAAAAQW5kcm9pZE1hbmlmZXN0LnhtbKSYS2ybx7XHf0PqbVmW4...BwAACigAAAAA",
        "name": "sphinx_1.7.2-1.dsc"
    },
    {
        "content": "UEsDBBQACAAIAAAAAAAAAAAAAAAAAAAAAAATAAAAQW5kcm9pZE1hbmlmZXN0LnhtbKSYS2ybx7XHf0PqbVmW4...BwAACigAAAAA",
        "name": "sphinx_1.7.2-1.changes"
    }
]

This adds the name field to the proposal in #743, because debsign needs the file extension. Restrictions on the name field and number of files is documented here and aim to limit the potential for path/directory traversal and DoS.

Signers that shell out have to decide how to map the named files to arguments. It doesn't provide a way to group or partition args for commands that take multiple variable args e.g. cmd --json-inputs a.json b.json c.json ... --csv-input d.csv e.csv ..., but our two immediate use cases don't require that flexibility.

  • Add a new signer interface:
// MultipleFileSigner is an interface to a signer that signs multiple
// files in one signing operation
type MultipleFileSigner interface {
	SignFiles(files []NamedUnsignedFile, options interface{}) ([]NamedSignedFile, error)
	GetDefaultOptions() interface{}
}

where NamedUnsignedFile and NamedSignedFile encode the signing operation in types to prevent misuse and are both aliased to the marshaled version of the named file format:

type namedFile struct {
	Name  string
	Bytes []byte
}
  • wire the new signing interface to /sign/files as originally proposed
  • compute and log input and output SHA2 hashes for each input and output file as in the original proposal

Add a debsign mode to the gpg2 signer #744

  • implemented as a new debsign signing mode that:
    • creates a tmp dir on signer init / autograph boot; loads the keys; writes a gpg.conf file (because we can't pass args to gpg2 via debsign); is cleaned up in the at exit handler
    • reuses the existing global gpg lock, because debsign calls gpg or gpg2
    • only supports /sign/files for end users (/sign/data will on sign the hardcoded monitoring input)
    • does not accept files with the .commands extension. debsign accepts .commandsfiles, but [we don't use them](https://github.com/mozilla-services/autograph/issues/744#issuecomment-933661284) and it appears to support runningrm` and other commands, which we'd like to avoid.
  • to avoid a breaking config change, existing gpg signers will use the current gpg2 mode when one is not provided
  • for each request it writes input files to a separate temp dir; calls debsign on them; write the gpg passphrase to stdin repeatedly (keeping it off disk as before); reads the clear signed input files; deletes the temp dir

Other changes

@g-k g-k force-pushed the fix-743-multi-file-744-debsign-support branch 7 times, most recently from 545c40d to c847624 Compare October 4, 2021 19:09
@coveralls
Copy link

coveralls commented Oct 4, 2021

Pull Request Test Coverage Report for Build 7412

  • 169 of 259 (65.25%) changed or added relevant lines in 4 files are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 71.27%

Changes Missing Coverage Covered Lines Changed/Added Lines %
main.go 0 1 0.0%
handlers.go 64 87 73.56%
signer/signer.go 0 29 0.0%
signer/gpg2/gpg2.go 105 142 73.94%
Files with Coverage Reduction New Missed Lines %
signer/gpg2/gpg2.go 6 80.46%
Totals Coverage Status
Change from base Build 7400: 0.2%
Covered Lines: 3401
Relevant Lines: 4772

💛 - Coveralls

@g-k g-k force-pushed the fix-743-multi-file-744-debsign-support branch 2 times, most recently from aa0b072 to ee12150 Compare October 5, 2021 13:54
@g-k g-k marked this pull request as ready for review October 5, 2021 14:17
@g-k g-k requested a review from ajvb October 5, 2021 14:17
@g-k
Copy link
Contributor Author

g-k commented Oct 5, 2021

r? @ajvb

Copy link
Contributor

@ajvb ajvb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking awesome! Great tests and docs are making this a breeze to review!

This is just a first pass. Tomorrow I want to spend a bit more time reading through the core of the multiple signer and gpg code, but has some initial CR comments and questions I thought I'd share right away.

bin/run_integration_tests.sh Outdated Show resolved Hide resolved
docs/endpoints.md Outdated Show resolved Hide resolved
docs/endpoints.md Outdated Show resolved Hide resolved
handlers.go Show resolved Hide resolved
handlers_test.go Show resolved Hide resolved
@ajvb ajvb self-requested a review October 6, 2021 18:44
ajvb
ajvb previously approved these changes Oct 7, 2021
Copy link
Contributor

@ajvb ajvb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🎉

Just have two comments related to the use of os.RemoveAll() in the new gpg signing code.

signer/gpg2/gpg2.go Outdated Show resolved Hide resolved
signer/gpg2/gpg2_test.go Show resolved Hide resolved
ajvb
ajvb previously approved these changes Oct 7, 2021
Copy link
Contributor

@ajvb ajvb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(re-approving after new commits dismissed last approval)

@g-k
Copy link
Contributor Author

g-k commented Oct 7, 2021

(re-approving after new commits dismissed last approval)

TY! I still need to squash this PR too.

@g-k g-k force-pushed the fix-743-multi-file-744-debsign-support branch 2 times, most recently from 6ada7d2 to d575751 Compare October 8, 2021 18:10
@g-k g-k force-pushed the fix-743-multi-file-744-debsign-support branch from d575751 to 25589ce Compare October 8, 2021 18:11
@g-k g-k merged commit 0edcdc8 into main Oct 12, 2021
@g-k g-k deleted the fix-743-multi-file-744-debsign-support branch October 12, 2021 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

debsign support support signing and returning multiple files in a signing request
3 participants